<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Bai 2.23</title>
</head>

<body>
<?php
	function Giai_pt_bac_nhat($a,$b)
	{	//return vsn: vo so nghiem; vn: vo nghiem;
		//tra ve gia tri neu co nghiem
		return $a==0?($b==0?"vsn":"vn"):(-$b/$a);
	}
	if(isset($_POST['a'])&&isset($_POST['b']) && isset($_POST['c']))
	{
		$a=$_POST['a'];
		$b=$_POST['b'];
		$c=$_POST['c'];
		if($a==0)
		{
			$tinh=Giai_pt_bac_nhat($b,$c);
			$nghiem=$tinh!="vsn"?($tinh!="vn")?"x = $tinh":"Phương trình vô nghiệm":"Phương trình có vô số nghiệm";
		}
		else
		{
			$delta=($b*$b)-4*$a*$c;
			if($delta<0)
				$nghiem="Phương trình vô nghiệm";
			elseif($delta==0)
				$nghiem="x1 = x2 = ".((-$b)/(2*$a));
			else
			{
				$kq1=(-$b+sqrt($delta))/(2*$a);
				$kq2=((-$b)-sqrt($delta))/(2*$a);
				$nghiem="x1 = $kq1, x2 = $kq2";
			}
		}
	}
?>
<form id="form1" name="form1" method="post" action="Bai2_23.php">
  <table width="350" border="0" align="center" cellpadding="0" cellspacing="0">
    <tr style="text-align: center">
      <td colspan="2" bgcolor="#996600" style="color:#FC0">GIẢI PHƯƠNG TRÌNH BẬC HAI</td>
    </tr>
    <tr bgcolor="#FFFFCC">
      <td nowrap="nowrap">Phương trình:</td>
      <td nowrap="nowrap"><input name="a" type="text" id="a" value="<?php echo $_POST['a'];?>" size="5" maxlength="10" />x<sup>2</sup> + 
          <input name="b" type="text" id="b" value="<?php echo $_POST['b'];?>" size="5" maxlength="10" />x 
        + 
          <input name="c" type="text" id="c" value="<?php echo $_POST['c'];?>" size="5" maxlength="10" /> 
        = 0</td>
    </tr>
    <tr bgcolor="#FFFFCC">
      <td nowrap="nowrap">Nghiệm:</td>
      <td nowrap="nowrap"><input name="nghiem" type="text" id="nghiem" style="background-color:#0F9" value="<?php echo $nghiem;?>" size="50" readonly="readonly" /></td>
    </tr>
    <tr bgcolor="#FFFFCC" style="text-align: center">
      <td colspan="2"><input type="submit" name="submit" id="submit" value="Giải phương trình" /></td>
    </tr>
  </table>
</form>
</body>
</html>